# -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import fields, osv
from openerp.tools.translate import _
import openerp.addons.decimal_precision as dp

class stock_produce_cost_update(osv.osv_memory):
    _inherit = "stock.produce.cost.update"
    
    def post_update(self,cr, uid, ids, prod_ids, date_from, date_to, company_id, context=None):
        resu = super(stock_produce_cost_update, self).post_update(cr, uid, ids, prod_ids, date_from, date_to, company_id, context=context)
        #更新焊点数数据
        cr.execute('''
            update stock_move a
                set solder_cnt = b.solder_cnt, solder_cnt_total = b.solder_cnt*a.product_qty
            from product_product b, stock_picking c
            where a.product_id = b.id
            and a.picking_id = c.id
            and a.state='done'
            and c.order_type in('mrp_produce_in','mrp_produce_return')
            and (a.location_id != a.location_dest_id)
            and b.id in %s
            and a.date >= %s
            and a.date <= %s    
            and a.company_id = %s  
            ''',(tuple(prod_ids),date_from,date_to,company_id))
        return resu
        
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
